<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    function mynew(Fun, ...args) {
      let obj = {}
      obj.__proto__ = Fun.prototype
      let result = Fun.apply(obj, args)
      return result instanceof Object ? result : obj
    }
    function Parent(name, age) {
      this.name = name
      this.age = age
    }
    Parent.prototype.getName = function () {
      console.log(this.name)
    }
    let p1 = new Parent('zhen', 28)
    let p2 = mynew(Parent, 'zhen22', '29')
    console.log(p1)
    console.log(p2)

    // new的过程
    let myNew2 = function (Fun, ...args) {
      let obj = {}
      obj.__proto__ = Fun.prototype
      let result = Fun.apply(obj, args)
      return result instanceof Object ? result : obj
    }
  </script>
</html>
